package thread;

public class ThreadDemo19 {
    public static void main(String[] args) {
        Object object = new Object();
        Thread t1 = new Thread(() -> {
            //线程1负责进行等待
            System.out.println("t1 wait之前");
            try {
                synchronized (object) {
                    object.wait();
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("t1 wait之后");
        });

        Thread t2 = new Thread(() -> {
            //线程2负责唤醒
            System.out.println("t2 notify之前");
                synchronized (object) {
                    object.notify();
                }
            System.out.println("t2 notify之后");
        });
        t1.start();
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        t2.start();
    }
}
